<?php

namespace Home\Model;
use Think\Model;
class NewsModel extends Model{
    public function NewsAdd($post,$file){
        if(!$file['error']){
            $arr = array(
                'rootPath'  => WORKING_PATH.UPLOAD_ROOT_PATH
                );
            $upload = new \Think\Upload($arr);
            $info = $upload -> uploadOne($file);
            if($info){
                $post['cover_img']= UPLOAD_ROOT_PATH . $info['savepath'].$info['savename'];
            }
        }
        $post['time'] = time();
        // var_dump($post);die;
        return $this->add($post);
    }
    
    public function NewsEdit($post,$file){
        if(!$file['error']){
            $arr = array(
                'rootPath'  => WORKING_PATH.UPLOAD_ROOT_PATH
                );
            $upload = new \Think\Upload($arr);
            $info = $upload -> uploadOne($file);
            if($info){
                $post['cover_img']= UPLOAD_ROOT_PATH . $info['savepath'].$info['savename'];
            }
        }
        // var_dump($post);die;
        return $this->save($post);
    }
}






